package hu;

import java.util.*;

public class card_hu {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] str1 = sc.nextLine().split(" ");
        String[] str2 = sc.nextLine().split(" ");
        int n = str1.length;
        int[] used = new int[n];
        int ans = 0;
        for (int i = 0; i < n; i++) {
            ans = Math.max(ans, dfs(str1, str2, i, used, 1));
        }
        System.out.println(ans);
    }
    public static int dfs(String[] str1, String[] str2, int i, int[] used, int ans){
        if(used[i] == 1 || i >= str1.length){
            return ans - 1;
        }
        int re = ans;
        used[i] = 1;
        for (int j = 0; j < str1.length; j++) {
            if(i != j && used[j] == 0){
                if(str1[i].equals(str1[j]) || str2[i].equals(str2[j])){
                    int t = dfs(str1, str2, j, used, ans + 1);
                    re = Math.max(re, t);
                }
            }
        }
        used[i] = 0;
        return re;
    }

}

/*
1 4 1 4 5
r y b r b

1 4 3 6
r y b g


 */